home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / SYQUEST / SQHDX / FMT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  4.2 KB  |  202 lines

  1. /* fmt.c */
  2.  
  3.  
  4. #include "obdefs.h"
  5. #include "defs.h"
  6. #include "part.h"
  7. #include "hdx.h"
  8. #include "addr.h"
  9.  
  10.  
  11. extern char sbuf[];
  12. extern int rebootp;
  13.  
  14.  
  15. /*
  16.  * These constants are used in a heuristic that determines
  17.  * if the format parameter information in the boot sector
  18.  * is intact.  (See fmtpok()).
  19.  */
  20. #define    MAXCYLS        4096        /* max number of cylinders */
  21. #define    MINCYLS        100        /* minimum number of cylinders */
  22. #define    MAXHEADS    16        /* max number of heads */
  23. #define    MINHEADS    2        /* minimum number of heads */
  24. #define    MAXLZ        16        /* max landing zone value */
  25. #define    MAXRT        2        /* max step-rate code */
  26.  
  27.  
  28. /*
  29.  * These are the default format parameters;
  30.  * they are for a 20Mb Mutsubuishi drive.
  31.  *
  32.  * If we change drives, this might have to be changed.
  33.  *
  34.  */
  35. HINFO deffmt = {
  36.     0x264,        /* 612 cylinders */
  37.     4,        /* 4 heads */
  38.     0x264,        /* no reduced write-current cylinder */
  39.     0x264,        /* no write precomp cylinder */
  40.     10,        /* landing zone position = 10 */
  41.     2,        /* use buffered seeks */
  42.     1,        /* interleave = 1 */
  43.     17        /* 17 sectors per track */
  44. };
  45.  
  46.  
  47. /*
  48.  * Report format error.
  49.  *
  50.  */
  51. formaterr(dev)
  52. int dev;
  53. {
  54.     char *pdev="X";
  55.     
  56.     *pdev = dev + '0';
  57.     (cantform[FMTDEV].ob_spec)->te_ptext = pdev;
  58.     cantform[FMTERROK].ob_state = NORMAL;
  59.     execform(cantform);
  60.     return ERROR;
  61. }
  62.  
  63.  
  64. /*
  65.  * Set format parameters in a
  66.  * root sector image.
  67.  * 6-13-88  only set size of hard disk.
  68.  *
  69.  */
  70. sfmtparm(image, size)
  71. char *image;
  72. long size;
  73. {
  74.     ((RSECT *)(image + 0x200 - sizeof(RSECT)))->hd_siz = size;
  75. }
  76.  
  77.  
  78. /*
  79.  * Determine if format parameters are good;
  80.  * return OK if they appear to be,
  81.  * ERROR if they don't appear to be.
  82.  *
  83.  */
  84. fmtpok(fmtparm)
  85. HINFO *fmtparm;
  86. {
  87.     if (fmtparm->hi_cc > MAXCYLS ||
  88.     fmtparm->hi_cc < MINCYLS ||
  89.     fmtparm->hi_dhc > MAXHEADS ||
  90.     fmtparm->hi_dhc < MINHEADS ||
  91.     fmtparm->hi_lz > MAXLZ ||
  92.     fmtparm->hi_rt > MAXRT)
  93.         return ERROR;
  94.  
  95.     return OK;
  96. }
  97.  
  98.  
  99. /*
  100.  * Setup default format parameters in hinfo;
  101.  * (REAL C compilers do this with a structure assignment...)
  102.  *
  103.  */
  104. fdefault(hinfop)
  105. HINFO *hinfop;
  106. {
  107.     hinfop->hi_cc = deffmt.hi_cc;
  108.     hinfop->hi_dhc = deffmt.hi_dhc;
  109.     hinfop->hi_rwcc = deffmt.hi_rwcc;
  110.     hinfop->hi_wpc = deffmt.hi_wpc;
  111.     hinfop->hi_lz = deffmt.hi_lz;
  112.     hinfop->hi_rt = deffmt.hi_rt;
  113.     hinfop->hi_in = deffmt.hi_in;
  114.     hinfop->hi_spt = deffmt.hi_spt;
  115. }
  116.  
  117.  
  118. /*
  119.  * Set mode information on drive.
  120.  *
  121.  */
  122. ms(dev, hinfo)
  123. int dev;
  124. HINFO *hinfo;
  125. {
  126.     int i;
  127.     char *p;
  128.     SETMODE mb;
  129.     extern long mode_set();
  130.  
  131.     /* initialize parameter structure */
  132.     p = (char *)&mb;
  133.     for (i = sizeof(SETMODE); i--;)
  134.     *p++ = 0;
  135.     mb.smd_8 = 0x08;
  136.     mb.smd_1 = 0x01;
  137.     mb.smd_bs[1] = 0x02;    /* block size = 512 */
  138.  
  139.     cpw(&mb.smd_cc[0], hinfo->hi_cc);
  140.     mb.smd_dhc = hinfo->hi_dhc;
  141.     cpw(&mb.smd_rwc[0], hinfo->hi_rwcc);
  142.     cpw(&mb.smd_wpc[0], hinfo->hi_wpc);
  143.     mb.smd_lz = hinfo->hi_lz;
  144.     mb.smd_rt = hinfo->hi_rt;
  145.  
  146.     return (int)mode_set(dev, &mb);
  147. }
  148.  
  149.  
  150. /*
  151.  * Move `w' to unaligned location.
  152.  *
  153.  */
  154. cpw(d, w)
  155. char *d;
  156. UWORD w;
  157. {
  158.     char *s;
  159.  
  160.     s = (char *)&w;
  161.     d[0] = s[0];
  162.     d[1] = s[1];
  163. }
  164.  
  165.  
  166. /*
  167.  * Return format parameters in `hinfo', based on
  168.  * the format parameter name `fpnam'.
  169.  *
  170.  * return 0 on OK,
  171.  * -1 on [CANCEL].
  172.  *
  173.  */
  174. gfparm(modesel, hinfop, fpnam)
  175. int *modesel;
  176. HINFO *hinfop;
  177. char *fpnam;
  178. {
  179.     long num;
  180.     char name[128];
  181.  
  182.     strcpy(name, fpnam);
  183.     if (wgetent(fpnam, NULL) == ERROR) {
  184.         nofmt[NOSCHFOK].ob_state = NORMAL;
  185.         (nofmt[NOSCHFMT].ob_spec)->te_ptext = name;
  186.         execform(nofmt);
  187.     return ERROR;
  188.     }
  189.  
  190.     fdefault(hinfop);
  191.     if (wgetnum("cy", &num) == OK) hinfop->hi_cc = (UWORD)num;
  192.     if (wgetnum("hd", &num) == OK) hinfop->hi_dhc = (BYTE)num;
  193.     if (wgetnum("rw", &num) == OK) hinfop->hi_rwcc = (UWORD)num;
  194.     if (wgetnum("wp", &num) == OK) hinfop->hi_wpc = (UWORD)num;
  195.     if (wgetnum("lz", &num) == OK) hinfop->hi_lz = (BYTE)num;
  196.     if (wgetnum("rt", &num) == OK) hinfop->hi_rt = (BYTE)num;
  197.     if (wgetnum("in", &num) == OK) hinfop->hi_in = (BYTE)num;
  198.     if (wgetnum("sp", &num) == OK) hinfop->hi_spt = (BYTE)num;
  199.     if (wgetnum("md", &num) == OK) *modesel = (UWORD)num;
  200.     return OK;
  201. }
  202.